package useless.wecker;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Calendar;

public class Database {

    public Database() throws Exception{
        throw new Exception("Dont you instantiate this class!!!11elf");
    }
    
    public static String getCurrentTimeString() {
        Calendar cal = Calendar.getInstance();
        String hour = String.valueOf(cal.get(cal.HOUR_OF_DAY));
        String minute = String.valueOf(cal.get(cal.MINUTE));
        String second = String.valueOf(cal.get(cal.SECOND));
        if (hour.length() == 1) hour = "0"+hour;
        if (minute.length() == 1) minute = "0"+minute;
        if (second.length() == 1) second = "0"+second;
       
        return hour + ":" + minute + ":" + second;
    }
    public static String getNewZeitString() throws IOException {
        final String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12";
        URL url = new URL(UselessWecker.SERVER_URL);
        URLConnection conn = url.openConnection();
        conn.addRequestProperty("User-Agent", userAgent);

        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String str, str1;
        str = new String();
        while ((str1 = in.readLine()) != null) {
            str = str + str1;
        }
        in.close();
        return str;
    }

    public static Weckzeit getNewWeckzeit() throws NumberFormatException, IOException {
        String zeit = getNewZeitString();
        String[] z = zeit.split(";");
        int hour = Integer.parseInt(z[0]);
        int minute = Integer.parseInt(z[1]);
        Weckzeit ret = new Weckzeit(hour, minute);
        return ret;
    }

}
